package cn.larry.demo.validator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import cn.larry.demo.domain.Party;


public class PartyValidator implements Validator {

	private Validator personValidator;

	@Autowired
	public PartyValidator(Validator personValidator) {
		super();
		this.personValidator = personValidator;
	}

	@Override
	public boolean supports(Class<?> clazz) {
		return Party.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "location", "neither empty nor white space is allowed");
		errors.pushNestedPath("person");
		ValidationUtils.invokeValidator(personValidator, target, errors);
	}

}
